package com.design.alex.iterator;

/**
 * @ClassName : NameRepository
 * @Description : todo
 * @Author : Alex
 * @Date: 2020-02-19 14:29
 */
public class NameRepository implements Container {

    public String names[] = {"Robert","John","Julie","Lora","Alex","Danny"};

    @Override
    public Iterator getIterator() {
        return new NameIterator();
    }

    private class NameIterator implements Iterator {
        int index = 0;

        @Override
        public boolean hasNext() {
            if (index < names.length) {
                return true;
            }
            return false;
        }

        @Override
        public Object next() {
            if (this.hasNext()) {
                return names[index++];
            }
            return null;
        }
    }

}
